/**
 * Created by guo.xiaomin on 2017-12-03.
 */
var messageUtil = require('../common/utils/messageUtil');
var operationService = require('../services/operationService');

exports.getCommissionH5Flag = function (req, res) {

    operationService.getCommissionH5Flag(function(err, results) {
        if (err) {
            logger.error('Failed to getCommissionH5Flag ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to getCommissionH5Flag ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.setCommissionH5Flag = function (req, res) {
    var setValue = req.body.setValue;
    operationService.setCommissionH5Flag(setValue, function(err, results) {
        if (err) {
            logger.error('Failed to setCommissionH5Flag ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to setCommissionH5Flag ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};


exports.getCommissionH5UserFlag = function (req, res) {

    operationService.getCommissionH5UserFlag(function(err, results) {
        if (err) {
            logger.error('Failed to getCommissionH5UserFlag ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to getCommissionH5UserFlag ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.setCommissionH5UserFlag = function (req, res) {
    var setValue = req.body.setValue;
    operationService.setCommissionH5UserFlag(setValue, function(err, results) {
        if (err) {
            logger.error('Failed to setCommissionH5UserFlag ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to setCommissionH5UserFlag ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.isAllowCommissionH5User = function (req, res) {
    var userId = req.body.userId;
    operationService.isAllowCommissionH5User(userId, function(err, results) {
        if (err) {
            logger.error('Failed to isAllowCommissionH5User ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to isAllowCommissionH5User ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.addAllowCommissionH5User = function (req, res) {
    var userId = req.body.userId;
    operationService.addAllowCommissionH5User(userId, function(err, results) {
        if (err) {
            logger.error('Failed to addAllowCommissionH5User ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to addAllowCommissionH5User ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.removeAllowCommissionH5User = function (req, res) {
    var userId = req.body.userId;
    operationService.removeAllowCommissionH5User(userId, function(err, results) {
        if (err) {
            logger.error('Failed to removeAllowCommissionH5User ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to removeAllowCommissionH5User ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.getAllAllowCommissionH5User = function (req, res) {
    operationService.getAllAllowCommissionH5User(function(err, results) {
        if (err) {
            logger.error('Failed to getAllAllowCommissionH5User ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to getAllAllowCommissionH5User ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.clearAllowCommissionH5User = function (req, res) {
    operationService.clearAllowCommissionH5User(function(err, results) {
        if (err) {
            logger.error('Failed to clearAllowCommissionH5User ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to clearAllowCommissionH5User ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.isAllowCommissionH5UserList = function (req, res) {
    var userIdList = req.body.userIdList;
    operationService.isAllowCommissionH5UserList(userIdList, function(err, results) {
        if (err) {
            logger.error('Failed to isAllowCommissionH5UserList ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to isAllowCommissionH5UserList ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.addAllowCommissionH5UserList = function (req, res) {
    var userIdList = req.body.userIdList;
    operationService.addAllowCommissionH5UserList(userIdList, function(err, results) {
        if (err) {
            logger.error('Failed to addAllowCommissionH5UserList ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to addAllowCommissionH5UserList ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.removeAllowCommissionH5UserList = function (req, res) {
    var userIdList = req.body.userIdList;
    operationService.removeAllowCommissionH5UserList(userIdList, function(err, results) {
        if (err) {
            logger.error('Failed to removeAllowCommissionH5UserList ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to removeAllowCommissionH5UserList ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.getSmsVerificationCode = function (req, res) {
    var mobilePhone = req.body.mobilePhone; // 手机号
    var type = req.body.type; // 验证码类型(注册，忘记密码，修改密码)
    operationService.getSmsVerificationCode(mobilePhone, type, function(err, results) {
        if (err) {
            logger.error('Failed to getSmsVerificationCode ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to getSmsVerificationCode ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};

exports.getRedisValueByKey = function (req, res) {
    var redisKey = req.body.redisKey; // 手机号
    operationService.getRedisValueByKey(redisKey, function(err, results) {
        if (err) {
            logger.error('Failed to getRedisValueByKey ---' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message, ''));
        } else {
            logger.debug('success to getRedisValueByKey ---');
            res.json(messageUtil.composeSucceededMessage(req, null, results, ''));
        }
    });

};